<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="ID">
              <a-input placeholder="请输入ID" v-model="queryParam.userId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户昵称">
              <a-input placeholder="请输入用户昵称" v-model="queryParam.userName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核类型">
              <j-dict-select-tag placeholder="请选择审核类型" v-model="queryParam.auditType" dictCode="user_data_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核状态">
              <j-dict-select-tag placeholder="请选择审核状态" v-model="queryParam.status" dictCode="audit_status"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="申请日期">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" @click="batchAudit('2')">批量通过</a-button>
      <a-button type="primary" @click="batchAudit('3')">批量拒绝</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="contentSlot" slot-scope="text,record">
          <span v-if="record.auditType=='1'">
            <img :src="text" :preview="record.id" height="30px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </span>
          <span v-else-if="record.auditType=='3'">
            <audio ref="audioPlayer" :src="text" style="height: 40px" controls></audio>
          </span>
          <span v-else-if="record.auditType=='4'">
            <img v-for="item in text.split(',')" :src="item" :preview="record.id" height="30px" alt="" style="margin-left: 5px"/>
          </span>
          <span v-else>
            {{text}}
          </span>
        </template>
        <template slot="statusSlot" slot-scope="text, record">
          <div v-if="record.status === '1'" style="color: #169bd5">{{text}}</div>
          <div v-else-if="record.status === '2'" style="color: #000000">{{text}}</div>
          <div v-else style="color: red">{{text}}</div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="record.status=='1'" @click="dataAudit(record.id,'2')">审核通过</a>
          <a-divider v-if="record.status=='1'" type="vertical" />
          <a v-if="record.status=='1'" @click="dataAudit(record.id,'3')">审核拒绝</a>
          <a-divider v-if="record.status=='1'" type="vertical" />
          <a @click="openAuditInfo(record)">自动审核信息</a>
        </span>
      </a-table>
    </div>
    <AuditInfo ref="AuditInfo"></AuditInfo>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'
  import AuditInfo from '../../AuditInfo'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'DataAuditList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      AuditInfo
    },
    data () {
      return {
        description: '用户资料自动审核管理界面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'用户id',
            align:"center",
            dataIndex: 'userId'
          },
          {
            title:'用户昵称',
            align:"center",
            dataIndex: 'userName'
          },
          {
            title:'审核类型',
            align:"center",
            dataIndex: 'auditType_dictText'
          },
          {
            title:'审核内容',
            align:"center",
            dataIndex: 'content',
            scopedSlots: { customRender: 'contentSlot' }
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'status_dictText',
            scopedSlots: { customRender: 'statusSlot' }
          },
          {
            title:'申请时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/user/dataAudit/rglist",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },

      //查看审核内容
      openAuditInfo(record){
        this.$refs.AuditInfo.visible=true;
        this.$refs.AuditInfo.getAuditInfo(record.id,"1");//1代表个人资料审核
      },

      //批量审核
      batchAudit(type){
        if(this.selectedRowKeys.length==0){
          this.$message.warning("请至少选择一条记录进行审核");
          return;
        }
        for (let i = 0; i < this.selectionRows.length; i++) {
          if(this.selectionRows[i].status!=1){
            this.$message.warning("只能选择”待审核“的数据操作");
            return;
          }
        }
        this.dataAudit(this.selectedRowKeys.join(","),type);
      },
      //审核
      dataAudit(ids,type){
        this.loading = true;
        getAction('/user/dataAudit/dataAudit', {ids: ids,type:type}).then(({success, result, message}) => {
          if (success) {
            this.loadData();
            this.onClearSelected();
            this.$message.success(message)
          } else {
            this.$message.warning(message)
          }
        }).finally(() => this.loading = false)
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>